package com.ywk.miaohsa.controller;

import com.ywk.miaohsa.domain.MiaoshaUser;
import com.ywk.miaohsa.result.Result;
import com.ywk.miaohsa.service.MiaoshaUserService;
import com.ywk.miaohsa.vo.PasswordVo;
import com.ywk.miaohsa.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    MiaoshaUserService miaoshaUserService;

    @RequestMapping("/modifyUserInfo")
    @ResponseBody
    public Result<UserInfoVo> modifyUserInfo(HttpServletRequest request,MiaoshaUser miaoshaUser, @Valid @RequestBody UserInfoVo userVo){
        UserInfoVo user=miaoshaUserService.modifyUserInfo(request,miaoshaUser,userVo);
        return Result.success(user);
    }

    @RequestMapping("/modifyPassword")
    @ResponseBody
    public Result<String> modifyPassword(HttpServletRequest request,MiaoshaUser miaoshaUser, @Valid @RequestBody PasswordVo psw){
        miaoshaUserService.modifyPassword(request,miaoshaUser,psw);
        return Result.success("success");
    }
}
